home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume6 / crc-check < prev    next >
Encoding:
Text File  |  1989-03-07  |  18.8 KB  |  731 lines

  1. Newsgroups: comp.sources.misc
  2. From: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  3. Subject: v06i059: file checker
  4. Keywords: crc, files
  5. Organization: Branch Technology, Ann Arbor, MI
  6. Reply-To: zeeff@b-tech.ann-arbor.mi.us (Jon Zeeff)
  7.  
  8. Posting-number: Volume 6, Issue 59
  9. Submitted-by: zeeff@b-tech.ann-arbor.mi.us (Jon Zeeff)
  10. Archive-name: crc-check
  11.  
  12. [A set of crc programs.  This came to me labeled as a "file system checker",
  13. but it's no fsck.  ++bsa]
  14.  
  15. This is a set of programs to check for unexpected file system 
  16. corruption or security breaches.  It's nice to be able to say that you 
  17. know all your files are as they should be.
  18.  
  19. #! /bin/sh
  20. # This is a shell archive.  Remove anything before this line, then unpack
  21. # it by saving it into a file and typing "sh file".  To overwrite existing
  22. # files, type "sh file -c".  You can also feed this as standard input via
  23. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  24. # will see the following message at the end:
  25. #        "End of shell archive."
  26. # Contents:  Makefile README crc.c crc_check.c find_crc
  27. # Wrapped by zeeff@b-tech on Sun Feb 26 12:10:25 1989
  28. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  29. if test -f Makefile -a "${1}" != "-c" ; then 
  30.   echo shar: Will not over-write existing file \"Makefile\"
  31. else
  32. echo shar: Extracting \"Makefile\" \(241 characters\)
  33. sed "s/^X//" >Makefile <<'END_OF_Makefile'
  34. X
  35. XCC=cc 
  36. XCFLAGS = -O 
  37. XLDFLAGS =
  38. X
  39. X
  40. XSRCS=crc.c crc_check.c
  41. XOBJS=crc.o crc_check.o
  42. X
  43. Xcrc: $(OBJS)
  44. X    $(CC) -o crc crc.o $(CFLAGS) $(LDFLAGS) 
  45. X    $(CC) -o crc_check crc_check.o $(CFLAGS) $(LDFLAGS) 
  46. X
  47. Xclean:
  48. X    rm -f crc.tmp crc.files *.o crc crc_check
  49. X
  50. END_OF_Makefile
  51. if test 241 -ne `wc -c <Makefile`; then
  52.     echo shar: \"Makefile\" unpacked with wrong size!
  53. fi
  54. # end of overwriting check
  55. fi
  56. if test -f README -a "${1}" != "-c" ; then 
  57.   echo shar: Will not over-write existing file \"README\"
  58. else
  59. echo shar: Extracting \"README\" \(1283 characters\)
  60. sed "s/^X//" >README <<'END_OF_README'
  61. X
  62. XThis is a set of programs to check for unexpected file system 
  63. Xcorruption or security breaches.  It's nice to be able to say that you 
  64. Xknow all your files are as they should be.  Mark Mendel wrote most of 
  65. Xcrc.c and I wrote crc_check.c.  It's written for Sys V, but BSD 
  66. Xshouldn't be hard.  
  67. X
  68. X
  69. XTo use it:
  70. X
  71. X1) you first create a crc list with the script find_crc.  You can
  72. Xmodify it and add grep -v to the pipe to change the file systems that
  73. Xit checks.   The end result is a file "crc.tmp".
  74. X
  75. X2) You can now use crc_check to compare this crc.tmp file to a crc list
  76. Xcreated earlier called crc.files.  If everything is ok, you can mv 
  77. Xcrc.tmp to crc.files.  It is expected that you will want to use grep -v
  78. Xon the output of crc_check to cut down on the noise.
  79. X
  80. XNote that you can use a -i option when running crc to change the 
  81. Xinitial crc value.  If you don't tell anyone what this is, you can 
  82. Xmake it nearly impossible for anyone to modify a file and then adjust 
  83. Xthe crc value to the old one.  To really do it right, you need to 
  84. X
  85. X1) Run find_crc in single user mode (unless you modify the crc source).
  86. X2) Store all crc results offline.
  87. X3) Don't let anyone see your -i value or the crc results.
  88. X
  89. X
  90. XPlease send me any modifications you make.
  91. X
  92. XJon Zeeff
  93. Xzeeff@b-tech.ann-arbor.mi.us
  94. X
  95. X
  96. END_OF_README
  97. if test 1283 -ne `wc -c <README`; then
  98.     echo shar: \"README\" unpacked with wrong size!
  99. fi
  100. # end of overwriting check
  101. fi
  102. if test -f crc.c -a "${1}" != "-c" ; then 
  103.   echo shar: Will not over-write existing file \"crc.c\"
  104. else
  105. echo shar: Extracting \"crc.c\" \(9918 characters\)
  106. sed "s/^X//" >crc.c <<'END_OF_crc.c'
  107. X/* updcrc(3), crc(1) - calculate crc polynomials
  108. X *
  109. X * Calculate, intelligently, the CRC of a dataset incrementally given a 
  110. X * buffer full at a time.
  111. X * 
  112. X * Usage:
  113. X *     newcrc = updcrc( oldcrc, bufadr, buflen )
  114. X *         unsigned int oldcrc, buflen;
  115. X *         char *bufadr;
  116. X *
  117. X * Compiling with -DTEST creates a program to print the CRC of stdin to stdout.
  118. X * Compile with -DMAKETAB to print values for crctab to stdout.  If you change
  119. X *    the CRC polynomial parameters, be sure to do this and change
  120. X *    crctab's initial value.
  121. X *
  122. X * Notes:
  123. X *  Regards the data stream as an integer whose MSB is the MSB of the first
  124. X *  byte recieved.  This number is 'divided' (using xor instead of subtraction)
  125. X *  by the crc-polynomial P.
  126. X *  XMODEM does things a little differently, essentially treating the LSB of
  127. X * the first data byte as the MSB of the integer. Define SWAPPED to make
  128. X * things behave in this manner.
  129. X *
  130. X * Author:    Mark G. Mendel, 7/86
  131. X *        UUCP: ihnp4!umn-cs!hyper!mark, GEnie: mgm
  132. X */
  133. X
  134. X#define TEST
  135. X
  136. X/* The CRC polynomial.
  137. X * These 4 values define the crc-polynomial.
  138. X * If you change them, you must change crctab[]'s initial value to what is
  139. X * printed by initcrctab() [see 'compile with -DMAKETAB' above].
  140. X */
  141. X
  142. X/* Value used by:                CITT    XMODEM    ARC      */
  143. X#define    P     0xA001     /* the poly:    0x1021    0x1021    A001    */
  144. X#define INIT_CRC 0L     /* init value:    -1    0    0    */
  145. X#define SWAPPED         /* bit order:    undef    defined    defined */
  146. X#define W    16     /* bits in CRC:16    16    16    */
  147. X
  148. X/* data type that holds a W-bit unsigned integer */
  149. X#if W <= 16
  150. X#  define WTYPE    unsigned short
  151. X#else
  152. X#  define WTYPE   unsigned long
  153. X#endif
  154. X
  155. X/* the number of bits per char: don't change it. */
  156. X#define B    8
  157. X
  158. Xstatic WTYPE crctab[1<<B] = /* as calculated by initcrctab() */ {
  159. X   0x0,  0xc0c1,  0xc181,  0x140,  0xc301,  0x3c0,  0x280,  0xc241,
  160. X   0xc601,  0x6c0,  0x780,  0xc741,  0x500,  0xc5c1,  0xc481,  0x440,
  161. X   0xcc01,  0xcc0,  0xd80,  0xcd41,  0xf00,  0xcfc1,  0xce81,  0xe40,
  162. X   0xa00,  0xcac1,  0xcb81,  0xb40,  0xc901,  0x9c0,  0x880,  0xc841,
  163. X   0xd801,  0x18c0,  0x1980,  0xd941,  0x1b00,  0xdbc1,  0xda81,  0x1a40,
  164. X   0x1e00,  0xdec1,  0xdf81,  0x1f40,  0xdd01,  0x1dc0,  0x1c80,  0xdc41,
  165. X   0x1400,  0xd4c1,  0xd581,  0x1540,  0xd701,  0x17c0,  0x1680,  0xd641,
  166. X   0xd201,  0x12c0,  0x1380,  0xd341,  0x1100,  0xd1c1,  0xd081,  0x1040,
  167. X   0xf001,  0x30c0,  0x3180,  0xf141,  0x3300,  0xf3c1,  0xf281,  0x3240,
  168. X   0x3600,  0xf6c1,  0xf781,  0x3740,  0xf501,  0x35c0,  0x3480,  0xf441,
  169. X   0x3c00,  0xfcc1,  0xfd81,  0x3d40,  0xff01,  0x3fc0,  0x3e80,  0xfe41,
  170. X   0xfa01,  0x3ac0,  0x3b80,  0xfb41,  0x3900,  0xf9c1,  0xf881,  0x3840,
  171. X   0x2800,  0xe8c1,  0xe981,  0x2940,  0xeb01,  0x2bc0,  0x2a80,  0xea41,
  172. X   0xee01,  0x2ec0,  0x2f80,  0xef41,  0x2d00,  0xedc1,  0xec81,  0x2c40,
  173. X   0xe401,  0x24c0,  0x2580,  0xe541,  0x2700,  0xe7c1,  0xe681,  0x2640,
  174. X   0x2200,  0xe2c1,  0xe381,  0x2340,  0xe101,  0x21c0,  0x2080,  0xe041,
  175. X   0xa001,  0x60c0,  0x6180,  0xa141,  0x6300,  0xa3c1,  0xa281,  0x6240,
  176. X   0x6600,  0xa6c1,  0xa781,  0x6740,  0xa501,  0x65c0,  0x6480,  0xa441,
  177. X   0x6c00,  0xacc1,  0xad81,  0x6d40,  0xaf01,  0x6fc0,  0x6e80,  0xae41,
  178. X   0xaa01,  0x6ac0,  0x6b80,  0xab41,  0x6900,  0xa9c1,  0xa881,  0x6840,
  179. X   0x7800,  0xb8c1,  0xb981,  0x7940,  0xbb01,  0x7bc0,  0x7a80,  0xba41,
  180. X   0xbe01,  0x7ec0,  0x7f80,  0xbf41,  0x7d00,  0xbdc1,  0xbc81,  0x7c40,
  181. X   0xb401,  0x74c0,  0x7580,  0xb541,  0x7700,  0xb7c1,  0xb681,  0x7640,
  182. X   0x7200,  0xb2c1,  0xb381,  0x7340,  0xb101,  0x71c0,  0x7080,  0xb041,
  183. X   0x5000,  0x90c1,  0x9181,  0x5140,  0x9301,  0x53c0,  0x5280,  0x9241,
  184. X   0x9601,  0x56c0,  0x5780,  0x9741,  0x5500,  0x95c1,  0x9481,  0x5440,
  185. X   0x9c01,  0x5cc0,  0x5d80,  0x9d41,  0x5f00,  0x9fc1,  0x9e81,  0x5e40,
  186. X   0x5a00,  0x9ac1,  0x9b81,  0x5b40,  0x9901,  0x59c0,  0x5880,  0x9841,
  187. X   0x8801,  0x48c0,  0x4980,  0x8941,  0x4b00,  0x8bc1,  0x8a81,  0x4a40,
  188. X   0x4e00,  0x8ec1,  0x8f81,  0x4f40,  0x8d01,  0x4dc0,  0x4c80,  0x8c41,
  189. X   0x4400,  0x84c1,  0x8581,  0x4540,  0x8701,  0x47c0,  0x4680,  0x8641,
  190. X   0x8201,  0x42c0,  0x4380,  0x8341,  0x4100,  0x81c1,  0x8081,  0x4040,
  191. X};
  192. X
  193. X
  194. Xvoid perror();
  195. Xchar *strcpy(); 
  196. Xvoid exit();
  197. X
  198. XWTYPE
  199. Xupdcrc( icrc, icp, icnt )
  200. XWTYPE icrc;
  201. Xunsigned char    *icp;
  202. Xint    icnt;
  203. X{
  204. X   register WTYPE crc = icrc;
  205. X   register unsigned char    *cp = icp;
  206. X   register int    cnt = icnt;
  207. X
  208. X   while ( cnt--) {
  209. X#ifndef SWAPPED
  210. X      crc = (crc << B) ^ crctab[(crc>>(W-B)) ^ *cp++];
  211. X#else
  212. X      crc = (crc >> B) ^ crctab[(crc & ((1<<B)-1)) ^ *cp++];
  213. X#endif 
  214. X   }
  215. X
  216. X   return( crc );
  217. X}
  218. X
  219. X
  220. X#ifdef MAKETAB
  221. X
  222. X#include <stdio.h>
  223. Xmain()
  224. X{
  225. X   initcrctab();
  226. X}
  227. X
  228. X
  229. Xinitcrctab()
  230. X{
  231. X   register int    b, i;
  232. X   WTYPE v;
  233. X
  234. X
  235. X   for ( b = 0; b <= (1 << B) - 1; ++b ) {
  236. X#ifndef SWAPPED
  237. X      for ( v = b << (W - B), i = B; --i >= 0; )
  238. X         v = v & ((WTYPE)1 << (W - 1)) ? (v << 1) ^ P : v << 1;
  239. X#else
  240. X      for ( v = b, i = B; --i >= 0; )
  241. X         v = v & 1 ? (v >> 1) ^ P : v >> 1;
  242. X#endif        
  243. X      crctab[b] = v;
  244. X
  245. X      (void)  printf( "0x%lx,", v & ((1L << W) - 1L));
  246. X      if ( (b & 7) == 7 )
  247. X         (void)  printf("\n" );
  248. X      else
  249. X         (void)  printf("  ");
  250. X   }
  251. X}
  252. X
  253. X
  254. X#endif
  255. X
  256. X#ifdef TEST
  257. X
  258. X#include <stdio.h>
  259. X#include <fcntl.h>
  260. X#include <sys/types.h>
  261. X#include <sys/stat.h>
  262. X#include <pwd.h>
  263. X#include <grp.h>
  264. X#define MAXBUF    4096
  265. X
  266. X#ifndef S_IRGRP
  267. X#define S_IRGRP    (S_IREAD >> 3)
  268. X#define S_IWGRP (S_IWRITE >> 3)
  269. X#define S_IXGRP (S_IEXEC >> 3)
  270. X#define S_IROTH (S_IREAD >> 6)
  271. X#define S_IWOTH (S_IWRITE >> 6)
  272. X#define S_IXOTH (S_IEXEC >> 6)
  273. X#endif
  274. X
  275. Xstruct stat stat_buf;
  276. Xint    initial_crc = INIT_CRC;
  277. X
  278. Xextern char    *optarg;
  279. Xextern int    optind;
  280. Xextern int    opterr;
  281. X
  282. Xmain( argc, argv )
  283. Xint    argc;
  284. Xchar    **argv;
  285. X{
  286. X   int    stats_flag = 0;
  287. X
  288. X   int    c;
  289. X
  290. X   if (argc == 1) {
  291. X      print_crc((char *)0, 0);
  292. X      return 0;
  293. X   }
  294. X
  295. X   /* process all arguments */
  296. X
  297. X   while ((c = getopt(argc, argv, "VvI:i:")) != EOF) {
  298. X
  299. X      switch (c) {
  300. X
  301. X      case 'V':
  302. X      case 'v':
  303. X         stats_flag = 1;
  304. X         break;
  305. X
  306. X      case 'I':
  307. X      case 'i':
  308. X         initial_crc = atoi(optarg);
  309. X         break;
  310. X
  311. X      default:
  312. X         (void) fprintf(stderr, "crc:  -v (verbose listing)\n");
  313. X         (void) fprintf(stderr, "      -i value (initial crc value)\n");
  314. X         exit(1);
  315. X      }
  316. X   }
  317. X
  318. X   for (; optind < argc ; optind++)
  319. X      print_crc(argv[optind], stats_flag);
  320. X
  321. X   return 0;
  322. X}
  323. X
  324. X
  325. Xprint_crc(name, stat_flag)
  326. Xchar    *name;
  327. Xint    stat_flag;
  328. X{
  329. X   int    fd;
  330. X   int    nr;
  331. X   unsigned char    buf[MAXBUF];
  332. X   WTYPE crc;
  333. X#ifdef MAGICCHECK
  334. X   WTYPE crc2;
  335. X#endif
  336. X
  337. X   fd = 0;
  338. X
  339. X   /* quietly ignore files we can't stat */
  340. X
  341. X   if (name != NULL && stat(name, &stat_buf) != 0)
  342. X      return;
  343. X
  344. X   /* don't do a crc on strange files */
  345. X
  346. X   crc = nr = 0;
  347. X
  348. X   if (name == NULL || (stat_buf.st_mode & S_IFMT) == S_IFREG) {
  349. X
  350. X      /* open the file and do a crc on it */
  351. X
  352. X      if (name != NULL && (fd = open( name, O_RDONLY )) < 0 ) {
  353. X         perror( name );
  354. X         exit( -1 );
  355. X      }
  356. X#ifdef MAGICCHECK
  357. X      crc2 = 
  358. X#endif
  359. X      crc = initial_crc;
  360. X
  361. X      while ( (nr = read( fd, (char *)buf, MAXBUF )) > 0 ) {
  362. X         crc = updcrc(crc, buf, nr );
  363. X      }
  364. X      (void) close(fd);
  365. X
  366. X   }
  367. X   if ( nr != 0 ) {
  368. X      perror( "read error" );
  369. X   } else {
  370. X      (void)  printf("%4.4x", (unsigned) crc );
  371. X      if (stat_flag)
  372. X         stats(name);
  373. X      else
  374. X         (void)  printf("\n");
  375. X
  376. X   }
  377. X
  378. X#ifdef MAGICCHECK
  379. X   /* tack one's complement of crc onto data stream, and
  380. X       continue crc calculation.  Should get a constant (magic number)
  381. X       dependent only on P, not the data.
  382. X     */
  383. X   crc2 = crc ^ -1L;
  384. X   for ( nr = W - B; nr >= 0; nr -= B ) {
  385. X      buf[0] = (crc2 >> nr);
  386. X      crc = updcrc(crc, buf, 1);
  387. X   }
  388. X
  389. X   /* crc should now equal magic */
  390. X   buf[0] = buf[1] = buf[2] = buf[3] = 0;
  391. X   (void)  printf( "magic test: %lx =?= %lx\n", crc, updcrc((WTYPE) - 1, buf, W / B));
  392. X#endif 
  393. X
  394. X
  395. X}
  396. X
  397. X
  398. Xstats(name)
  399. Xchar    *name;
  400. X{
  401. X
  402. X   struct passwd *entry;
  403. X   struct group *group_entry;
  404. X   static char    owner[20];
  405. X   static char    group[20];
  406. X   char    a_time[50];
  407. X
  408. X   struct passwd *getpwuid();
  409. X   struct group *getgrgid();
  410. X   char    *ctime();
  411. X
  412. X   static int    prev_uid = -9999;
  413. X   static int    prev_gid = -9999;
  414. X
  415. X   if (stat_buf.st_uid != prev_uid) {
  416. X      entry = getpwuid((int)stat_buf.st_uid);
  417. X      if (entry)
  418. X         (void) strcpy(owner, entry->pw_name);
  419. X      else
  420. X         (void) sprintf(owner, "%d", stat_buf.st_uid);
  421. X      prev_uid = stat_buf.st_uid;
  422. X   }
  423. X   if (stat_buf.st_gid != prev_gid) {
  424. X      group_entry = getgrgid((int)stat_buf.st_gid);
  425. X      if (group_entry)
  426. X         (void) strcpy(group, group_entry->gr_name);
  427. X      else
  428. X         (void) sprintf(group, "%d", stat_buf.st_gid);
  429. X      prev_gid = stat_buf.st_gid;
  430. X   }
  431. X
  432. X   (void) strcpy(a_time, ctime(&stat_buf.st_mtime));
  433. X   a_time[24] = '\0';
  434. X
  435. X   print_perm(stat_buf.st_mode);
  436. X
  437. X   (void)  printf(" %s\t%s\t%s %s\n", owner, group, a_time + 4, name);
  438. X
  439. X}
  440. X
  441. X
  442. Xprint_perm(perm)
  443. Xunsigned int    perm;
  444. X{
  445. X
  446. X   char    string[20];
  447. X   (void) strcpy(string, "----------");
  448. X
  449. X   switch (perm & S_IFMT) {
  450. X
  451. X   case S_IFDIR:
  452. X      string[0] = 'd';
  453. X      break;
  454. X
  455. X   case S_IFBLK:
  456. X      string[0] = 'b';
  457. X      break;
  458. X
  459. X   case S_IFCHR:
  460. X      string[0] = 'c';
  461. X      break;
  462. X
  463. X   case S_IFIFO:
  464. X      string[0] = 'p';
  465. X      break;
  466. X   }
  467. X   if (perm & S_IREAD)
  468. X      string[1] = 'r';
  469. X   if (perm & S_IWRITE)
  470. X      string[2] = 'w';
  471. X   if (perm & S_ISUID && perm & S_IEXEC)
  472. X      string[3] = 's';
  473. X   else if (perm & S_IEXEC)
  474. X      string[3] = 'x';
  475. X   else if (perm & S_ISUID)
  476. X      string[3] = 'S';
  477. X
  478. X   if (perm & S_IRGRP)
  479. X      string[4] = 'r';
  480. X   if (perm & S_IWGRP)
  481. X      string[5] = 'w';
  482. X   if (perm & S_ISUID && perm & S_IXGRP)
  483. X      string[6] = 's';
  484. X   else if (perm & S_IXGRP)
  485. X      string[6] = 'x';
  486. X   else if (perm & S_ISUID)
  487. X      string[6] = 'l';
  488. X
  489. X   if (perm & S_IROTH)
  490. X      string[7] = 'r';
  491. X   if (perm & S_IWOTH)
  492. X      string[8] = 'w';
  493. X   if (perm & S_ISVTX && perm & S_IXOTH)
  494. X      string[9] = 't';
  495. X   else if (perm & S_IXOTH)
  496. X      string[9] = 'x';
  497. X   else if (perm & S_ISVTX)
  498. X      string[9] = 'T';
  499. X
  500. X   (void) printf(" %s", string);
  501. X}
  502. X
  503. X#endif
  504. X
  505. END_OF_crc.c
  506. if test 9918 -ne `wc -c <crc.c`; then
  507.     echo shar: \"crc.c\" unpacked with wrong size!
  508. fi
  509. # end of overwriting check
  510. fi
  511. if test -f crc_check.c -a "${1}" != "-c" ; then 
  512.   echo shar: Will not over-write existing file \"crc_check.c\"
  513. else
  514. echo shar: Extracting \"crc_check.c\" \(4067 characters\)
  515. sed "s/^X//" >crc_check.c <<'END_OF_crc_check.c'
  516. X
  517. X/*
  518. X    This progam will compare two crc lists and report the differences.
  519. X    
  520. X    By Jon Zeeff (zeeff@b-tech.ann-arbor.mi.us)
  521. X
  522. X    Permission is granted to use this in any manner provided that    
  523. X    1) the copyright notice is left intact, 
  524. X    2) you don't hold me responsible for any bugs and 
  525. X    3) you mail me any improvements that you make.  
  526. X
  527. X
  528. X    report:
  529. X         corrupt    -    crc changed w/o date change
  530. X         replaced    -    crc + date changed
  531. X         perm        -    permissions changed
  532. X         own/grp    -    owner or group changed
  533. X     removed    -    
  534. X     added        -
  535. X
  536. XPrint the info for the new file except for deleted.
  537. X
  538. XUse:
  539. X
  540. Xfind / -print | sort | xargs crc -v > crc_file
  541. X
  542. Xto generate a crc list (crc.c should accompany this source).
  543. X
  544. XAssume that no files have tabs or spaces in the name.
  545. X
  546. X*/
  547. X
  548. X/* max size of line */
  549. X
  550. X#define BUF_SIZE 1124
  551. X
  552. X#include <stdio.h>
  553. X
  554. Xchar    *strrchr();
  555. Xvoid    exit();
  556. X
  557. Xchar    new_line[BUF_SIZE];
  558. Xchar    old_line[BUF_SIZE];
  559. X
  560. XFILE *new_file;
  561. XFILE *old_file;
  562. X
  563. Xmain(argc, argv)
  564. Xint    argc;
  565. Xchar    **argv;
  566. X{
  567. X   /*
  568. X
  569. X           If line =, read new line from each file
  570. X           else
  571. X           If date/perm/crc change, report and read new line from each file
  572. X           else
  573. X           If old_line < new_line, report file removed, read old line
  574. X           else
  575. X              report new line as added
  576. X              read new_line
  577. X        loop
  578. X*/
  579. X
  580. X   char    *new_ptr;
  581. X   char    *old_ptr;
  582. X
  583. X   if (argc != 3) {
  584. X      (void) printf("wrong number of arguments\n");
  585. X      (void) printf("crc_check old_crc_file new_crc_file\n");
  586. X      exit(1);
  587. X   }
  588. X   new_file = fopen(argv[2], "r");
  589. X   old_file = fopen(argv[1], "r");
  590. X
  591. X   if (new_file == NULL || old_file == NULL) {
  592. X      (void) printf("can't open input files\n");
  593. X      (void) printf("crc_check old_crc_file new_crc_file\n");
  594. X      exit(1);
  595. X   }
  596. X
  597. X   get_line(new_line);
  598. X   get_line(old_line);
  599. X
  600. X   for (; ; ) {
  601. X
  602. X      check_eof();
  603. X
  604. X      /* If equal, print nothing and get new lines */
  605. X
  606. X      if (strcmp(old_line, new_line) == 0) {
  607. X         get_line(new_line);
  608. X         get_line(old_line);
  609. X         continue;
  610. X      }
  611. X
  612. X      /* Compare just the file names */
  613. X
  614. X      new_ptr = strrchr(new_line, ' ');
  615. X      old_ptr = strrchr(old_line, ' ');
  616. X
  617. X      if (new_ptr == NULL || old_ptr == NULL) {
  618. X         (void) printf("Error in input data\n");
  619. X         exit(1);
  620. X      }
  621. X
  622. X      if (strcmp(old_ptr, new_ptr) == 0) {
  623. X
  624. X         new_ptr = strrchr(new_line, '\t');
  625. X         old_ptr = strrchr(old_line, '\t');
  626. X
  627. X         if (new_ptr == NULL || old_ptr == NULL) {
  628. X            (void) printf("Error in input data\n");
  629. X            exit(1);
  630. X         }
  631. X
  632. X         /* check crc change */
  633. X
  634. X         if (strncmp(new_line, old_line, 4) != 0)
  635. X            if (strcmp(new_ptr, old_ptr) == 0)
  636. X               (void) printf("corrupt  %s", new_line + 5);
  637. X            else
  638. X               (void) printf("replaced %s", new_line + 5);
  639. X
  640. X
  641. X         /* check permission chenage */
  642. X
  643. X         if (strncmp(new_line + 5, old_line + 5, 11) != 0)
  644. X            (void) printf("permiss  %s", new_line + 5);
  645. X
  646. X         /* check  owner/group */
  647. X
  648. X         if (strncmp(new_line+16, old_line+16, new_ptr - new_line - 15) != 0)
  649. X            (void) printf("own/grp  %s", new_line + 5);
  650. X
  651. X         get_line(new_line);
  652. X         get_line(old_line);
  653. X         continue;
  654. X      }
  655. X
  656. X
  657. X      if (strcmp(old_ptr, new_ptr) < 0) {
  658. X         (void) printf("removed  %s", old_line + 5);
  659. X         get_line(old_line);
  660. X         continue;
  661. X      }
  662. X
  663. X      (void) printf("added    %s", new_line + 5);
  664. X      get_line(new_line);
  665. X
  666. X   }
  667. X
  668. X}
  669. X
  670. X
  671. Xget_line(string)
  672. Xchar    *string;
  673. X{
  674. X   if (string == new_line)
  675. X      (void) fgets(string, BUF_SIZE, new_file);
  676. X   else
  677. X      (void) fgets(string, BUF_SIZE, old_file);
  678. X
  679. X}
  680. X
  681. X
  682. Xcheck_eof()
  683. X{
  684. X
  685. X   if (feof(new_file)) {
  686. X
  687. X      while (!feof(old_file)) {
  688. X         (void) printf("removed  %s", old_line + 5);
  689. X         (void) fgets(old_line, BUF_SIZE, old_file);
  690. X      }
  691. X      exit(0);
  692. X   } else if (feof(old_file)) {
  693. X      while (!feof(new_file)) {
  694. X         (void) printf("added    %s", new_line + 5);
  695. X         (void) fgets(new_line, BUF_SIZE, new_file);
  696. X      }
  697. X      exit(0);
  698. X   }
  699. X
  700. X}
  701. X
  702. X
  703. END_OF_crc_check.c
  704. if test 4067 -ne `wc -c <crc_check.c`; then
  705.     echo shar: \"crc_check.c\" unpacked with wrong size!
  706. fi
  707. # end of overwriting check
  708. fi
  709. if test -f find_crc -a "${1}" != "-c" ; then 
  710.   echo shar: Will not over-write existing file \"find_crc\"
  711. else
  712. echo shar: Extracting \"find_crc\" \(58 characters\)
  713. sed "s/^X//" >find_crc <<'END_OF_find_crc'
  714. X
  715. Xfind / -mount -print | sort | xargs crc -v > crc.tmp  
  716. X
  717. X
  718. END_OF_find_crc
  719. if test 58 -ne `wc -c <find_crc`; then
  720.     echo shar: \"find_crc\" unpacked with wrong size!
  721. fi
  722. chmod +x find_crc
  723. # end of overwriting check
  724. fi
  725. echo shar: End of shell archive.
  726. exit 0
  727. -- 
  728.   Jon Zeeff            zeeff@b-tech.ann-arbor.mi.us
  729.   Ann Arbor, MI            mailrus!b-tech!zeeff
  730.  
  731.